package com.ruoyi.web.controller.ora;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.ora.domain.UserWhite;
import com.ruoyi.ora.domain.VoiceFolder;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ora.domain.DeviceRelation;
import com.ruoyi.ora.service.IDeviceRelationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备关系Controller
 * 
 * @author liuwp
 * @date 2025-03-19
 */
@RestController
@RequestMapping("/ora/device_relation")
public class DeviceRelationController extends BaseController
{
    @Autowired
    private IDeviceRelationService deviceRelationService;

    /**
     * 查询设备关系列表
     */
    @PreAuthorize("@ss.hasPermi('ora:device_relation:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceRelation deviceRelation)
    {
        startPage();
        List<DeviceRelation> list = deviceRelationService.selectDeviceRelationList(deviceRelation);
        return getDataTable(list);
    }

    /**
     * 导出设备关系列表
     */
    @PreAuthorize("@ss.hasPermi('ora:device_relation:export')")
    @Log(title = "设备关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceRelation deviceRelation)
    {
        List<DeviceRelation> list = deviceRelationService.selectDeviceRelationList(deviceRelation);
        ExcelUtil<DeviceRelation> util = new ExcelUtil<DeviceRelation>(DeviceRelation.class);
        util.exportExcel(response, list, "设备关系数据");
    }

    /**
     * 获取设备关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('ora:device_relation:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(deviceRelationService.selectDeviceRelationById(id));
    }

    /**
     * 新增设备关系
     */
    @PreAuthorize("@ss.hasPermi('ora:device_relation:add')")
    @Log(title = "设备关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceRelation deviceRelation)
    {
        return toAjax(deviceRelationService.insertDeviceRelation(deviceRelation));
    }

    /**
     * 修改设备关系
     */
    @PreAuthorize("@ss.hasPermi('ora:device_relation:edit')")
    @Log(title = "设备关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceRelation deviceRelation)
    {
        return toAjax(deviceRelationService.updateDeviceRelation(deviceRelation));
    }

    /**
     * 删除设备关系
     */
    @PreAuthorize("@ss.hasPermi('ora:device_relation:remove')")
    @Log(title = "设备关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceRelationService.deleteDeviceRelationByIds(ids));
    }

    @PreAuthorize("@ss.hasPermi('ora:device_relation:list')")
    @GetMapping("/query")
    public AjaxResult query(DeviceRelation deviceRelation)
    {
        deviceRelation.setUserId(SecurityUtils.getUserId());
        List<DeviceRelation> list = deviceRelationService.selectDeviceRelationList(deviceRelation);
        return AjaxResult.success(list);
    }

    @PreAuthorize("@ss.hasPermi('ora:device_relation:add')")
    @Log(title = "设备关系", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult addRelation(DeviceRelation deviceRelation)
    {
        deviceRelation.setUserId(SecurityUtils.getUserId());
//        deviceRelation.setFamilyId(SecurityUtils.getLoginUser().getUser().getFamilyId());
        return toAjax(deviceRelationService.insertDeviceRelation(deviceRelation));
    }
}
